using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;

namespace Boggle.Net.Model
{
    public static class Game
    {
        public const int MinimumWordLength = 3;

        public static IEnumerable<string> Dice
        {
            get
            {
                return new[]
                {
                    // New
                    //"AWOTOT", "TSDIYT", "FSAFPK", "RVTWEH", "BOAJBO", "PSCAOH", "QUIHNM", "TMUOIC",
                    //"HNZNHL", "TYTLRE", "SNEIEU", "WEENGH", "ISTOES", "ERXIDL", "AEANGE", "LYVRDE"

                    // Old
                    "AACIOT", "ABILTY", "ABJMOQ", "ACDEMP", "ACELRS", "ADENVZ", "AHMORS", "BIFORX", 
                    "DENOSW", "DKNOTU", "EEFHIY", "EGINTV", "EGKLUY", "EHINPS", "ELPSTU", "GILRUW"
                };
            }
        }

        public static int MaxQsPerGame
        {
            get { return Dice.SelectMany(dice => dice).Count(face => face == 'Q'); }
        }

        public static char[] SelectLetterFromEachDice(Func<int, int> randomSeries)
        {
            return Dice.Select(face => face[randomSeries(face.Length)]).ToArray();
        }

        public static char[] SelectJumbledLetters(Func<int, int> randomSeries)
        {
            return SelectLetterFromEachDice(randomSeries).Shuffle(randomSeries);
        }

        public static char[] SelectJumbledLetters(int seed)
        {
            return SelectJumbledLetters(new Random(seed).Next);
        }

        public static int ScoreLetterCount(int count)
        {
            Contract.Requires<ArgumentOutOfRangeException>(count >= 0);

            switch (count)
            {
                case 3:
                case 4:
                    return 1;
                case 5:
                    return 2;
                case 6:
                    return 3;
                case 7:
                    return 5;
            }

            return count < 8 ? 0 : 11;
        }
    }
}